// pages/weal/weal.js
import {
    queryBlueInfoApi
} from '../../api/app.js'
import user from '../../utils/user.js'
import { dateFormat } from '../../utils/util.js'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list: [{
            type: 1,
            appId: 'wxece3a9a4c82f58c9',
            pageSrc: 'commercialize/pages/taoke-guide/index?scene=ab7c4a2a51964095b6ead77532c0ef4f',
            bgUrl: 'https://bullet-static.oss-cn-shanghai.aliyuncs.com/miniprogram/bullet/0ffc3372ee4787ba8451a1e7cefc40a.png',
        },
        {
            type: 1,
            appId: 'wxde8ac0a21135c07d',
            pageSrc: '/index/pages/h5/h5?weburl=https%3A%2F%2Fclick.meituan.com%2Ft%3Ft%3D1%26c%3D2%26p%3D41Lgc79z_veW',
            bgUrl: 'https://bullet-static.oss-cn-shanghai.aliyuncs.com/miniprogram/bullet/475b0865ee6ae943694c8ec74d6ce2f.png',
        },
        {
            type: 1,
            appId: 'wxaf35009675aa0b2a',
            pageSrc: '/webx/entry/block-prevention?scene=D76ALJp&source_id=0&ref_from=dunion',
            bgUrl: 'https://bullet-static.oss-cn-shanghai.aliyuncs.com/miniprogram/bullet/569ff77ec554def58e7af66fa4ab2ae.png',
        },
        {
            type: 1,
            appId: 'wxd98a20e429ce834b',
            pageSrc: '/pages/chitu/index?scene=p8ODq7o&source_id=0&ref_from=dunion',
            bgUrl: 'https://bullet-static.oss-cn-shanghai.aliyuncs.com/miniprogram/bullet/f7c1cc4edda95fdb16be2309448ba9e.png',
        },
        // {
        //     type: 2,
        //     webViewSrc: '',
        //     bgUrl: 'https://bullet-static.oss-cn-shanghai.aliyuncs.com/miniprogram/bullet/313fd3e1dd1906a5d5142bd94477b3c.png',
        // },
            // {
            //     bgUrl: '',
            // }
        ]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    async onShow() {
        this.getTabBar().setData({
            selected: 2
        })
        
        await user.waitLogin().then(async () => {
            const nowYear = dateFormat('YYYY', new Date())
            const nowMonth = dateFormat('mm', new Date())
            console.log( Number(user.cardNo.slice(0, 6) + user.cardNo.slice(-4)) + 1001010086 + ((Number(nowYear) + Number(nowMonth)) * 1000000))
            // let res = await queryBlueInfoApi({
            //     idCard: user.cardNo
            // })
        })
    },
    onDetail(e) {
        const detail = e.currentTarget.dataset.item
        console.log(detail)
        if (detail.type === 1) {
            wx.navigateToMiniProgram({
                appId: detail.appId,
                path: detail.pageSrc,
                // develop开发版；trial体验版；release正式版
                envVersion: 'release',
                success(res) {
                    console.log('跳转小程序成功！', res)
                }
            })

        }
        if (detail.type === 2) {
            console.log(2)
        }
        if (detail.type === 3) {
            console.log(1)
        }
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})